package com.twu.biblioteca;

import java.util.ArrayList;

/**
 * Created by Rob on 11/09/2014.
 */
public class Library {
    public ArrayList<Book> booksForBorrowing;
    public ArrayList<Book> booksToBeReturned;
    public ArrayList<Movie> moviesForBorrowing;
    public ArrayList<Movie> moviesToBeReturned;

    public Library(){
        booksForBorrowing = new ArrayList<Book>();
        booksToBeReturned = new ArrayList<Book>();
        moviesForBorrowing = new ArrayList<Movie>();
        moviesToBeReturned = new ArrayList<Movie>();
        createBookList();
        createMovieList();
    }

    public void createBookList(){
        booksForBorrowing.add(new Book("To Kill A Mockingbird", "Harper Lee", 1960));
        booksForBorrowing.add(new Book("Nineteen Eighty-Four", "George Orwell", 1949));
        booksForBorrowing.add(new Book("Harry Potter and the Philosophers Stone", "J.K Rowling", 1997));
        booksForBorrowing.add(new Book("Pride and Prejudice", "Jane Austen", 1813));
        booksForBorrowing.add(new Book("Animal Farm", "George Orwell", 1945));
        booksForBorrowing.add(new Book("The Hobbit", "J.R.R Tolkien", 1937));
        booksForBorrowing.add(new Book("The Catcher in the Rye", "J.D Salinger", 1951));
        booksForBorrowing.add(new Book("The Great Gatsby", "F. Scott Fitzgerald", 1925));
    }

    public void createMovieList(){
        moviesForBorrowing.add(new Movie("Inception", "Christopher Nolan", 2010, 9));
        moviesForBorrowing.add(new Movie("The Devil Wears Prada", "David Frankel", 2006, 7));
        moviesForBorrowing.add(new Movie("Catch Me If You Can", "Steven Speilburg", 2002, 8));
        moviesForBorrowing.add(new Movie("The Holiday", "Nancy Meyers", 2006, 7));
        moviesForBorrowing.add(new Movie("Hulk", "Ang Lee", 2003, 6));
        moviesForBorrowing.add(new Movie("Pretty Woman", "Garry Marshall", 1990, 7));
        moviesForBorrowing.add(new Movie("The Matrix", "The Wachowski Bro's",1999, 9));
        moviesForBorrowing.add(new Movie("Happy Feet", "George Miller", 2006, 7));
    }

    public void addBook(Book BookToAdd){
        booksForBorrowing.add(BookToAdd);
    }

    public ArrayList<Book> getBookList(){
        return booksForBorrowing;
    }

    public void removeBook(int bookNumberInList){
        booksToBeReturned.add(booksForBorrowing.get(bookNumberInList));
        booksForBorrowing.remove(booksForBorrowing.get(bookNumberInList));
    }

    public int getBookNumber(Book bookToGetNumberInList){
        if (bookToGetNumberInList == null){
            return -1;
        }
        for(int x = 0;x < booksForBorrowing.size(); x++){
            if(booksForBorrowing.get(x).getName().equals(bookToGetNumberInList.getName())){
                return x;
            }
        }
        return -2;
    }

    public void printBooks(){
        for(Book book:booksForBorrowing){
            String formattedBookDetails = book.toString();
            System.out.println(formattedBookDetails);
        }
    }

    public void printMovies(){
        for(Movie movie:moviesForBorrowing){
            String formattedMovieDetails = movie.toString();
            System.out.println(formattedMovieDetails);
        }
    }

    public void printRentedBooks(User currentUser){
        for(Book book:booksToBeReturned){
            String formattedMovieDetails = book.toString();
            System.out.println("..              " + currentUser.getName() + formattedMovieDetails);
        }
    }

}
